package com.kgame5.xtank3d.effect.myemitters {
import kgame5.k3d.core.math.Vector3D;
import kgame5.k3d.core.obj3d.node3d.Node3D;
import kgame5.k3d.pars.myflint.geom.Vector3DFlint;
import kgame5.k3d.pars.myflint.zones.SphereZone;
import kgame5.k3d.pars.myflint.zones.Zone3D;
import kgame5.kgu.spacial.SpacialManager;
import kgame5.kmath.MathDG;

import com.kgame5.xtank3d.effect.MyEmitter;
import com.kgame5.xtank3d.resource.ResourceManagerX;

/**
 * @author kk
 * 炮弹炸开的小碎片,做的很好！
 */
public class ShotChipsEmitter extends MyEmitter{
	
	public function ShotChipsEmitter() {
		//T.p("ShotChipsEmitter");
		//碎片产生的区域
		var pZone:Zone3D=new SphereZone(new Vector3DFlint(0, 0, 0), 32, 16);
		var rZone:Zone3D=new SphereZone(Vector3DFlint.ZERO,360);
		var rvZone:Zone3D=new SphereZone(Vector3DFlint.ZERO,20);
		//爆炸中心
		var c:Vector3D=new Vector3D(0,0,0);
										
		var count:int=MathDG.random(4,6);
		for(var i:int=0;i<count;i++){
			
			var md_chip:Node3D=ResourceManagerX.getInstance().getBlastChip();//  Factory3D.CreateSprite3D("MyMc_BlastChip");
			
			//位置
			var p:Vector3DFlint=pZone.getLocation();
			md_chip.posi.fill(p.x,p.y,p.z);
			//T.p("粒子初始位置",p);
			//速度
			var v:Vector3D=md_chip.posi.clone();
			v.sub(c);
			
			v.y=MathDG.random(18,24);//速度不为负的，这样保证粒子是溅射的
			
			var speedMag:int=MathDG.linearFunc(v.magnitude(),28,128);//this.getExplorSpeed(v.magnitude(),64,16);
			//T.p(speedMag);
	 		v.normalize();
			v.mul(speedMag);
			//T.p(v);
			md_chip.velo.copy(v);
			//T.p("粒子速度：",v)
			//加速度
			md_chip.ti.hardVO.v3d_a.y= SpacialManager.G;
			
			//旋转
			var r:Vector3DFlint=rZone.getLocation();
			md_chip.rot.fill(r.x, r.y, r.z);
			
			//旋转速度
			//var rv:Vector3DFlint=rvZone.getLocation();
			//md_chip.hardVO.v3d_rv.fill(rv.x, rv.y, rv.z);
			
			//缩放
			var scale:Number=MathDG.random(5, 8)/10;
			md_chip.scale.mul(scale);
			
			//生命
			md_chip.life=-1;//落地
			
			//--添加到世界
			md_g.addChild(md_chip);
		}
	}
}
}
